from django.db import models

class BookInfoManager(models.Manager): 
    def create_book(self, title, pub_date):
        book = self.create(btitle = title,bpub_date = pub_date,bread=0,bcommet=0,isDelete = False)
        return book

    # 使用管理器更改查询集
    def get_queryset(self):
        return super(BookInfoManager, self).get_queryset().filter(isDelete = False)    
    

# Create your models here.
class BookInfo(models.Model):
    btitle = models.CharField(max_length=20)
    bpub_date = models.DateTimeField()
    bread = models.IntegerField(default=0)
    bcommet = models.IntegerField(default=0)
    isDelete = models.BooleanField(default=False)
    
    # 定义模型类时指定管理器
    bookmanager = BookInfoManager()

# 设置元信息
    # class Meta():
    #     # 数据表的名称就变成book
    #     db_table='book'   
    #     ordering=['id']
    


class HeroInfo(models.Model):
    hname = models.CharField(max_length=20)
    hgender = models.BooleanField(default=True)
    isDelete = models.BooleanField(default=False)
    hcontent = models.CharField(max_length=100)
    hbook = models.ForeignKey('BookInfo',on_delete=models.CASCADE)